# include <bits/stdc++.h>
# define mid ((l + r) >> 1)
# define MAXN 100023
using namespace std;
inline int gn() {
    int k = 0, f = 1;
    char c = getchar();
    for(;!isdigit(c); c = getchar()) if(c == '-') f = -1;
    for(; isdigit(c); c = getchar()) k = k * 10 + c - '0';
    return k * f;
}

struct edge { 
    int to;
    edge *ne;
    inline edge(){ 
        to = 0;
        ne = NULL;
    }
    inline edge(int to_, edge *ne_) { 
        to = to_;
        ne = ne_;
    }
}*head[MAXN];

inline void addedge(int fr, int to) { 
    edge *e = new edge(to, head[fr]);
    head[fr] = e;
}

int n, m, fa[MAXN];

inline void init() { 
    for(int i = 1; i < n; i++) { 
        addedge(fa[i], i);
        addedge(i, fa[i]);
    }
}

int siz[MAXN], son[MAXN], dep[MAXN];// siz, son, dep
int q[MAXN], l, r;
inline void bfs() { 
    memset(son, -1, sizeof(son));
    fa[0] = -1;
    l = r = 1;
    q[1] = 0;
    dep[0] = 1;
    while(l <= r) { 
        int u = q[l++];
        siz[u] = 1;
        for(edge *e = head[u]; e; e = e->ne) { 
            int v = e->to;
            if(dep[v]) continue;
            dep[v] = dep[u] + 1;
            q[++r] = v;
        }
    }
    for(int i = r; i; i--) { 
        siz[fa[q[i]]] += siz[q[i]];
        if(siz[son[fa[q[i]]]] <= siz[q[i]] && q[i]) son[fa[q[i]]] = q[i];
    }
}


int dfn[MAXN], top[MAXN], id;//dfn, top;
void dfs(int u, int tp) { 
    top[u] = tp;
    dfn[u] = ++id;
    if(!~son[u]) return;
    dfs(son[u], tp);
    for(edge *e = head[u]; e; e = e->ne) { 
        int v = e->to;
        if(~top[v]) continue;
        dfs(v, v);
    }
}

struct node { 
    int sum, lz;// -1: none 0: remove 1: install
    node *ls, *rs;
    inline node() { 
        lz = -1;
        sum = 0, ls = rs = NULL;
    }
}*root;

node *build(int l, int r) { 
    node *x = new node();
    if(l ^ r) { 
        x->ls = build(l, mid);
        x->rs = build(mid + 1, r);
    }
    return x;
}

inline void pushdown(node *x, int l, int r) { 
    if(~x->lz) { 
        if(x->lz) { 
            x->ls->sum = mid - l + 1;
            x->rs->sum = r - mid;
            x->ls->lz = x->lz;
            x->rs->lz = x->lz;
        } else { 
            x->ls->sum = x->rs->sum = x->ls->lz = x->rs->lz = 0;
        }
        x->lz = -1;
    }
}

inline void pushup(node *x) { 
    x->sum = x->ls->sum + x->rs->sum;
}

int query(node *x, int l, int r, int s, int t) { 
    if(l ^ r) pushdown(x, l, r);
    if(l == s && r == t) { 
        return x->sum;
    } else { 
        if(t <= mid) return query(x->ls, l, mid, s, t);
        else if(s > mid) return query(x->rs, mid + 1, r, s, t);
        else return query(x->ls, l, mid, s, mid) + query(x->rs, mid + 1, r, mid + 1, t);
    }
}

void change(node *x, int l, int r, int s, int t, bool op) { 
    if(l ^ r) pushdown(x, l, r);
    if(l == s && r == t) { 
        x->sum = op * (r - l + 1);
        x->lz = op;
    } else { 
        if(t <= mid) change(x->ls, l, mid, s, t, op);
        else if(s > mid) change(x->rs, mid + 1, r, s, t, op);
        else { 
            change(x->ls, l, mid, s, mid, op);
            change(x->rs, mid + 1, r, mid + 1, t, op);
        }
        pushup(x);
    }
}   

inline int query_install(int k) { 
    int ans = 0;
    while(~k) { 
        ans += query(root, 1, n, dfn[top[k]], dfn[k]);
        k = fa[top[k]];
    }
    return ans;
}

inline void change_install(int k, bool op) { 
    while(~k) { 
        change(root, 1, n, dfn[top[k]], dfn[k], op);
        k = fa[top[k]];
    }
}

int main() { 
# ifndef LOCAL 
    freopen("manager.in", "r", stdin);
    freopen("manager.out", "w", stdout);
# else
    freopen("in", "r", stdin);
# endif
    n = gn();
    for(int i = 1; i < n; i++) fa[i] = gn();
    init();
    bfs();
    memset(top, -1, sizeof(top));
    dfs(0, 0);
    root = build(1, n);
    m = gn();
    for(int i = 1; i <= m; i++) { 
        char op[10];
        scanf("%s", op);
        if(op[0] == 'i') { 
            int k = gn();
            printf("%d\n", dep[k] - query_install(k));
            change_install(k, 1);
        } else if(op[0] == 'u') { 
            int k = gn();
            printf("%d\n", query(root, 1, n, dfn[k], dfn[k] + siz[k] - 1));
            change(root, 1, n, dfn[k], dfn[k] + siz[k] - 1, 0);
        }
    }
}
